home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Interfaces / PInterfaces / UGridView.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  31.6 KB  |  806 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
  2. { UGridView.p }
  3. { Copyright © 1987-1990 by Apple Computer Inc. All rights reserved. }
  4.  
  5. {$IFC UNDEFINED UsingIncludes}
  6. {$SETC UsingIncludes := FALSE}
  7. {$ENDC}
  8.  
  9. {$IFC NOT UsingIncludes}
  10. UNIT UGridView;
  11.  
  12.     INTERFACE
  13.         {$ENDC}
  14.  
  15.         {$IFC UNDEFINED __UGridView__}
  16.         {$SETC __UGridView__ := FALSE}
  17.         {$ENDC}
  18.  
  19.         {$IFC NOT __UGridView__}
  20.         {$SETC __UGridView__ := TRUE}
  21.  
  22.         { • Auto-Include the requirements for this unit's interface. }
  23.         {$SETC UGridViewIncludes := UsingIncludes}
  24.         {$SETC UsingIncludes := TRUE}
  25.         {$I+}
  26.         {$IFC UNDEFINED __UMacApp__} {$I UMacApp.p} {$ENDC}
  27.         {$SETC UsingIncludes := UGridViewIncludes}
  28.  
  29.         CONST
  30.  
  31.             { Booleans for Adornment }
  32.             kAdorn                = TRUE;
  33.             kDontAdorn            = FALSE;
  34.  
  35.             { Booleans for SetSelection }
  36.             kExtend             = TRUE;
  37.             kDontExtend         = FALSE;
  38.  
  39.             kHighlight            = TRUE;
  40.             kDontHighlight        = FALSE;
  41.  
  42.             kSelect             = TRUE;
  43.             kDeSelect            = FALSE;
  44.  
  45.         TYPE
  46.             GridCell            = Point;                { A cell is a QuickDraw point }
  47.  
  48.             GridViewPart        = (badChoice, inCell, inRow, inColumn, inVertex);
  49.  
  50. {--------------------------------------------------------------------------------------------------}
  51.  
  52.             RunArrayChunk        = RECORD
  53.                 count:                INTEGER;            { Number of consecutive items with this
  54.                                                          value }
  55.                 value:                INTEGER;            { The value represented by this chunk }
  56.                 END;
  57.  
  58.             ChunkArray            = ARRAY [0..100000] OF RunArrayChunk;
  59.             ChunkArrayPtr        = ^ChunkArray;            { Preferred }
  60.             ChunkArrayHandle    = ^ChunkArrayPtr;        { Preferred }
  61.             PChunkArray         = ChunkArrayPtr;        { Left in for compatibility (2.0) }
  62.             HChunkArray         = ChunkArrayHandle;     { Left in for compatibility (2.0) }
  63.  
  64.             TRunArray            = OBJECT (TObject)        { The run array class is used to maintain
  65.                                                          the column widths and row heights. Entries
  66.                                                          in the array are values for a given item,
  67.                                                          where the items are indexed from one.
  68.                                                          fNoOfItems indicates the number of items
  69.                                                          (and values) in the array. The values are
  70.                                                          maintained in "chunks" which lump together
  71.                                                          consecutive items with the same value. A
  72.                                                          variable length array, fChunks, is used to
  73.                                                          store the chunks. It is indexed from zero.
  74.                                                          }
  75.                 fLastItem:            INTEGER;            { cache the last item found }
  76.                 fLastChunk:         INTEGER;            { cache the last chunk found }
  77.  
  78.                 fLastTotal:         LONGINT;            { cache the last total calculated }
  79.                 fLastIndex:         INTEGER;            { cache the last index used }
  80.                 fNoOfItems:         INTEGER;            { Number of items (values) in this run-array
  81.                                                          }
  82.                 fTotal:             LONGINT;            { The sum of the values in the run array }
  83.                 fNoOfChunks:        INTEGER;            { Number of chunks in the run array }
  84.                 fChunks:            ChunkArrayHandle;    { A handle to the chunks themselves. }
  85.  
  86.                 PROCEDURE TRunArray.IRunArray;
  87.                 { Initializes a run array to have zero items. }
  88.  
  89.                 PROCEDURE TRunArray.Free; OVERRIDE;
  90.                 { Frees the fChunks field which is a handle to the chunks, before calling inherited
  91.                 Free. }
  92.  
  93.                 PROCEDURE TRunArray.InsertItems(firstItem, noOfItems: INTEGER;
  94.                                                 value: INTEGER);
  95.                 { Inserts the indicated items into the run array, all of which have the given value.
  96.                 }
  97.  
  98.                 PROCEDURE TRunArray.DeleteItems(firstItem, noOfItems: INTEGER);
  99.                 { Deletes the indicated items from the run array.}
  100.  
  101.                 FUNCTION TRunArray.FindChunk(item: INTEGER;
  102.                                              VAR chunk, indexInChunk: INTEGER;
  103.                                              VAR theTotal: LONGINT): BOOLEAN;
  104.                 { Returns information about a given item in the run array. chunk indicates the chunk
  105.                 in which the item is located, where zero is the first chunk in the run array.
  106.                 indexInChunk is the location of the item withinin the chunk. Note that the chunk
  107.                 indexes are one-based--the first item in the chunk is index 1. theTotal is the sum
  108.                 of values up to, but not including, the chunk in which the given item is located.
  109.                 FindChunk returns false if the given item is outside the range of items in the
  110.                 run-array (i.e. item < 1 or item > fNoOfItems), or the given item is not
  111.                 represented in a chunk (i.e. a bug).
  112.                 Example: Item    Value    Chunk    indexInChunk    theTotal
  113.                             1        05        0            1            000
  114.                             2        05        0            2            000
  115.                             3        20        1            1            010
  116.                             4        35        2            1            030
  117.                             5        35        2            2            030
  118.                             6        10        3            1            100
  119.                 }
  120.  
  121.                 FUNCTION TRunArray.FindItem(theTotal: LONGINT): INTEGER;
  122.                 { Returns the item number for which the sum of the values exceeds theTotal, or zero
  123.                 if theTotal is outside the sum of values represented by the run array.}
  124.  
  125.                 FUNCTION TRunArray.GetValue(item: INTEGER): INTEGER;
  126.                 { Returns the value for the given item. }
  127.  
  128.                 FUNCTION TRunArray.SumValues(firstItem, noOfItems: INTEGER): LONGINT;
  129.                 { Returns the sum of the values over the given items. }
  130.  
  131.                 PROCEDURE TRunArray.Fields(PROCEDURE
  132.                                            DoToField(fieldName: Str255;
  133.                                                      fieldAddr: Ptr;
  134.                                                      fieldType: INTEGER)); OVERRIDE;
  135.                 { Used by the Inspector and the Debugger to display the contents of this class's
  136.                 fields. }
  137.  
  138.                 END;
  139.  
  140. {--------------------------------------------------------------------------------------------------}
  141.  
  142.             GridViewTemplate    = PACKED RECORD
  143.                 numOfRows:            INTEGER;
  144.                 numOfCols:            INTEGER;
  145.                 rowHeight:            INTEGER;
  146.                 colWidth:            INTEGER;
  147.                 rowInset:            INTEGER;
  148.                 colInset:            INTEGER;
  149.                 adornRows:            BOOLEAN;
  150.                 adornCols:            BOOLEAN;
  151.                 singleSelection:    BOOLEAN;
  152.                 filler:             0..8191;
  153.                 END;
  154.             GridViewTemplatePtr = ^GridViewTemplate;
  155.  
  156.             TextGridViewTemplate = PACKED RECORD
  157.                 itsFontFace:        Style;
  158.                 itsFontSize:        INTEGER;
  159.                 itsFontColor:        RGBColor;
  160.                 itsFontName:        Str255;             { a variable length P-String }
  161.                 END;
  162.             TextGridViewTemplatePtr = ^TextGridViewTemplate;
  163.  
  164.             TGridView            = OBJECT (TView)        { TGridView forms the base class for a
  165.                                                          building block that allows the creation of
  166.                                                          views that can contain and manage cells,
  167.                                                          similar to a spreadsheet. }
  168.                 fNumOfRows:         INTEGER;            { number of rows }
  169.                 fNumOfCols:         INTEGER;            { number of columns }
  170.                 fColWidths:         TRunArray;            { bag containing col widths }
  171.                 fRowHeights:        TRunArray;            { bag containing row heights }
  172.                 fAdornRows:         BOOLEAN;            { Draw adornment for rows? }
  173.                 fAdornCols:         BOOLEAN;            { Draw adornment for columns? }
  174.                 fRowInset:            INTEGER;            { Number of pixels between cell rows }
  175.                 fColInset:            INTEGER;            { Number of pixels between cell cols }
  176.                 fSingleSelection:    BOOLEAN;            { only one cell selected at a time? }
  177.                 fSelections:        RgnHandle;            { Region of currently selected cells }
  178.                 fHLRegion:            RgnHandle;            { Region of cells to be highlighted. This
  179.                                                          will be different from fSelections while
  180.                                                          selection with the mouse is taking place.
  181.                                                          }
  182.                 fTempSelections:    RgnHandle;            { Used by SetSelectionRect }
  183.  
  184.                 PROCEDURE TGridView.IGridView(itsDocument: TDocument; { Its document }
  185.                                               itsSuperView: TView; { Its parent view }
  186.                                               itsLocation: VPoint; { Top, Left in parent's coords }
  187.                                               itsSize: VPoint;        { Ignored for sizeVariable }
  188.                                               itsHSizeDet, itsVSizeDet: SizeDeterminer; { Size
  189.                                                   determiners }
  190.                                               numOfRows: INTEGER; { number of rows initially }
  191.                                               numOfCols: INTEGER; { number of columns initially }
  192.                                               rowHeight: INTEGER; { Height for initial rows }
  193.                                               colWidth: INTEGER; { width for initial columns }
  194.                                               adornRows: BOOLEAN; { Adornment for Rows? }
  195.                                               adornCols: BOOLEAN; { Adornment for Columns? }
  196.                                               rowInset: INTEGER; { horizontal space between cells }
  197.                                               colInset: INTEGER; { vertical space between cells }
  198.                                               singleSelection: BOOLEAN); { single cell selection? }
  199.  
  200.                 { Initialize the gridview. If numOfRows or numOfCols is non-zero then the gridview is
  201.                 initialized to the specified size using rowHeight and colWidth if the sizedeterminer
  202.                 is sizeVariable. If either adorn is kDontAdorn, then that adorn will not be called. }
  203.  
  204.                 PROCEDURE TGridView.IRes(itsDocument: TDocument;
  205.                                          itsSuperView: TView;
  206.                                          VAR itsParams: Ptr); OVERRIDE;
  207.                 { Initialize the view template. }
  208.  
  209.                 PROCEDURE TGridView.WRes(theResource: ViewRsrcHndl;
  210.                                          VAR itsParams: Ptr); OVERRIDE;
  211.                 { Write this object out as a view resource. }
  212.  
  213.                 PROCEDURE TGridView.WriteRes(theResource: ViewRsrcHndl;
  214.                                              VAR itsParams: Ptr); OVERRIDE;
  215.                 { Set up the type and signature of this object and call WRes. }
  216.  
  217.                 PROCEDURE TGridView.Free; OVERRIDE;
  218.                 { Free the TGridView object }
  219.  
  220.                 {  Methods to OVERRIDE      }
  221.  
  222.                 {  Inherited Methods  (OVERRIDE)    }
  223.  
  224.                 PROCEDURE TGridView.CalcMinSize(VAR minSize: VPoint); OVERRIDE;
  225.                 { Sets the extent of the view. }
  226.  
  227.                 PROCEDURE TGridView.DoHighlightSelection(fromHL, toHL: HLState); OVERRIDE;
  228.                 { Do highlighting }
  229.  
  230.                 FUNCTION TGridView.DoMouseCommand(VAR theMouse: Point;
  231.                                                   VAR info: EventInfo;
  232.                                                   VAR hysteresis: Point): TCommand; OVERRIDE;
  233.                 { Handle mouse commands }
  234.  
  235.                 PROCEDURE TGridView.Draw(area: Rect); OVERRIDE;
  236.                 { Calls DrawRangeOfCells and AdornRow/Col as appropriate. }
  237.  
  238.                 {  UGridView Methods to OVERRIDE    }
  239.  
  240.                 PROCEDURE TGridView.AdornCol(aCol: INTEGER;
  241.                                              area: Rect);
  242.                 { If fAdornCol is TRUE, this method is called to draw the column adornments. }
  243.  
  244.                 PROCEDURE TGridView.AdornRow(aRow: INTEGER;
  245.                                              area: Rect);
  246.                 { If fAdornRow is TRUE, this method is called to draw the row  adornments. }
  247.  
  248.                 FUNCTION TGridView.CanSelectCell(aCell: GridCell): BOOLEAN;
  249.                 { This method checks to see if a cell can be seleced. By default, this method always
  250.                 returns TRUE. }
  251.  
  252.                 PROCEDURE TGridView.HighlightCells(theCells: RgnHandle;
  253.                                                    fromHL, toHL: HLState);
  254.                 { Highlights the cells in theCells according to the given highlight state. }
  255.  
  256.                 PROCEDURE TGridView.DrawRangeOfCells(startCell, stopCell: GridCell;
  257.                                                      aQDRect: Rect);
  258.                 { This method calls DrawCell for each cell in need of re-drawing. }
  259.  
  260.                 PROCEDURE TGridView.DrawCell(aCell: GridCell;
  261.                                              aQDRect: Rect);
  262.                 { This method draws each individual cell.  IT MUST BE OVERRIDDEN! }
  263.  
  264.                 {  General UGridView Methods     }
  265.  
  266.                 PROCEDURE TGridView.AllCellsDo(PROCEDURE
  267.                                                DoToCell(aCell: GridCell));
  268.                 { For every cell in the view perform "DoToCell". }
  269.  
  270.                 PROCEDURE TGridView.CellToVRect(aCell: GridCell;
  271.                                                 VAR aRect: VRect);
  272.                { Get the rectangle bounding a given cell. This includes the row and column insets. }
  273.  
  274.                 PROCEDURE TGridView.ColToVRect(aCol: INTEGER;
  275.                                                numOfCols: INTEGER;
  276.                                                VAR aRect: VRect);
  277.                 { Get the rectangle bounding the given columns. This includes the cells in the row or
  278.                 column and the row or column insets. }
  279.  
  280.                 PROCEDURE TGridView.RowToVRect(aRow: INTEGER;
  281.                                                numOfRows: INTEGER;
  282.                                                VAR aRect: VRect);
  283.                 { Get the rectangle bounding the given rows. This includes the cells in the row or
  284.                 column and the row or column insets. }
  285.  
  286.                 PROCEDURE TGridView.CellsToPixels(theCells, thePixels: RgnHandle);
  287.                 { Returns in thePixels a region that contains all of the cells in theCells. }
  288.  
  289.                 PROCEDURE TGridView.DelColAt(aCol: INTEGER;
  290.                                              numOfCols: INTEGER);
  291.                 { Delete the specified columns, starting at 'aCol' with the number to be deleted
  292.                 'numOfCols'.This causes a redraw of only the necessary cells. }
  293.  
  294.                 PROCEDURE TGridView.DelRowAt(aRow: INTEGER;
  295.                                              numOfRows: INTEGER);
  296.                 { Delete the specified rows, starting at 'aRow' with the number of to be deleted
  297.                 'numOfRows'.This causes a redraw of only the necessary cells. }
  298.  
  299.                 PROCEDURE TGridView.DelColFirst(numOfCols: INTEGER);
  300.                 { Delete the specified number of columns from the beginning of the list.This causes a
  301.                 redraw of only the necessary cells. }
  302.  
  303.                 PROCEDURE TGridView.DelRowFirst(numOfRows: INTEGER);
  304.                 { Delete the specified number of rows from the beginning of the list.This causes a
  305.                 redraw of only the necessary cells. }
  306.  
  307.                 PROCEDURE TGridView.DelColLast(numOfCols: INTEGER);
  308.                 { Delete the specified number of columns from the last cell of the list.This causes a
  309.                 redraw of only the necessary cells. }
  310.  
  311.                 PROCEDURE TGridView.DelRowLast(numOfRows: INTEGER);
  312.                 { Delete the specified number of rows from the last cell of the list.This causes a
  313.                 redraw of only the necessary cells. }
  314.  
  315.                 PROCEDURE TGridView.EachCellDo(startCell, stopCell: GridCell;
  316.                                                PROCEDURE
  317.                                                DoToCell(aCell: GridCell));
  318.                 { For each cell in the rectangle defined by startCell and stopCell perform
  319.                 "DoToCell". }
  320.  
  321.                 PROCEDURE TGridView.EachSelectedCellDo(PROCEDURE
  322.                                                        DoToCell(aCell: GridCell));
  323.                 { For each cell in the selected region perform "DoToCell". }
  324.  
  325.                 PROCEDURE TGridView.EachInRgn(aRgn: RgnHandle;
  326.                                               PROCEDURE
  327.                                               DoToCell(aCell: GridCell));
  328.                 { For each cell in the specified region perform "DoToCell". }
  329.  
  330.                 FUNCTION TGridView.FirstSelectedCell: GridCell;
  331.                 { Returns the top left cell in the selection range, if any }
  332.  
  333.                 FUNCTION TGridView.GetColWidth(aCol: INTEGER): INTEGER;
  334.                 { Return the width    for the specified  column. }
  335.  
  336.                 FUNCTION TGridView.GetRowHeight(aRow: INTEGER): INTEGER;
  337.                 { Return the height for the specified row . }
  338.  
  339.                 FUNCTION IdentifyPoint(theQDPoint: Point;
  340.                                        VAR aRow, aCol: INTEGER): GridViewPart;
  341.                 { Return the GridViewPart (inCell, inColumn, inRow, inVertex)
  342.                 in which the specified point lies. The "vertex" is the area
  343.                 where a row and column meet. }
  344.  
  345.                 PROCEDURE TGridView.InsColBefore(aCol: INTEGER;
  346.                                                  numOfCols: INTEGER;
  347.                                                  aWidth: INTEGER);
  348.                 { Insert the specified columns before the column given.The widths of the columns are
  349.                 all set to the specified aWidth. }
  350.  
  351.                 PROCEDURE TGridView.InsRowBefore(aRow: INTEGER;
  352.                                                  numOfRows: INTEGER;
  353.                                                  aHeight: INTEGER);
  354.                 { Insert the specified rows before the row given.The heights of the rows are all set
  355.                 to the specified aHeight. }
  356.  
  357.                 PROCEDURE TGridView.InsColFirst(numOfCols: INTEGER;
  358.                                                 aWidth: INTEGER);
  359.                 { Insert the specified number of columns at the beginning of the list.The widths of
  360.                 the columns are all set to the specified aWidth. }
  361.  
  362.                 PROCEDURE TGridView.InsRowFirst(numOfRows: INTEGER;
  363.                                                 aHeight: INTEGER);
  364.                 { Insert the specified number of rows at the beginning of the list.The heights of the
  365.                 rows are all set to the specified aHeight. }
  366.  
  367.                 PROCEDURE TGridView.InsColLast(numOfCols: INTEGER;
  368.                                                aWidth: INTEGER);
  369.                 { Insert the specified number columns at the end of the list.The widths of the
  370.                 columns are all set to the specified aWidth. }
  371.  
  372.                 PROCEDURE TGridView.InsRowLast(numOfRows: INTEGER;
  373.                                                aHeight: INTEGER);
  374.                 { Insert the specified number of rows at the end of the list.The heights of the rows
  375.                 are all set to the specified aHeight. }
  376.  
  377.                 PROCEDURE TGridView.InvalidateCell(aCell: GridCell);
  378.                 { Cause a cell to be marked invalid (in need of re-drawing). }
  379.  
  380.                 PROCEDURE TGridView.InvalidateSelection;
  381.                 { Cause the rectangle bounding the selections to be marked
  382.                 invalid (in need of re-drawing). }
  383.  
  384.                 FUNCTION TGridView.IsCellSelected(aCell: GridCell): BOOLEAN;
  385.                 { Check if the specified cell is currently selected. }
  386.  
  387.                 FUNCTION TGridView.LastSelectedCell: GridCell;
  388.                 { Returns the bottom right cell in the selection range, if any }
  389.  
  390.                 PROCEDURE TGridView.ScrollSelectionIntoView(redraw: BOOLEAN);
  391.                 { Scroll the specified rectangle into view. }
  392.  
  393.                 PROCEDURE TGridView.SetColWidth(aCol: INTEGER;
  394.                                                 numOfCols: INTEGER;
  395.                                                 aWidth: INTEGER);
  396.                 { Set the width of the specified columns to that given. }
  397.  
  398.                 PROCEDURE TGridView.SetRowHeight(aRow: INTEGER;
  399.                                                  numOfRows: INTEGER;
  400.                                                  aHeight: INTEGER);
  401.                 { Set the height of the specified rows to that given. }
  402.  
  403.                 PROCEDURE TGridView.SelectCell(theCell: GridCell;
  404.                                                extendSelection, highlight, select: BOOLEAN);
  405.                 { Set the current selection to the specified cell. Sets up a region and then calls
  406.                 SetSelection. }
  407.  
  408.                 PROCEDURE TGridView.SetEmptySelection(highlight: BOOLEAN);
  409.                 { Set the current selection to be empty or nothing. If highlight is kHighlight then
  410.                 the appropriate highlighting is performed. }
  411.  
  412.                 PROCEDURE TGridView.SetSelection(cellsToSelect: RgnHandle;
  413.                                                  extendSelection, highlight, select: BOOLEAN);
  414.                 { Set the current selections to the specified region. If extend is kExtend then
  415.                 cellsToSelect is "added" to that already selected, if highlight is kHighlight then
  416.                 cellsToSelect is highlighted as well. IF select is kSelect then cellsToSelect is
  417.                 selected, if kDeSelect then de-selected}
  418.  
  419.                 PROCEDURE TGridView.SetSelectionRect(left, top, right, bottom: INTEGER;
  420.                                                      extendSelection, highlight, select: BOOLEAN);
  421.                 { Set the current selections to the specified rectangle. and call SetSelection. }
  422.  
  423.                 PROCEDURE TGridView.SetSingleSelection(theSetting: BOOLEAN);
  424.                 { If TRUE then only one item/cell can be selected at a time }
  425.  
  426.                 FUNCTION TGridView.VPointToCell(aPoint: VPoint): GridCell;
  427.                 { Determine the cell in which a given point lies, or (0, 0) if the given point
  428.                 doesn't lie within any cell. }
  429.  
  430.                 FUNCTION TGridView.VPointToLastCell(aPoint: VPoint): GridCell;
  431.                 { Returns the cell in which the given point lies, or the last cell of the row/column
  432.                 if the horizontal/vertical coordinate lies beyond the last cell of the row/column.}
  433.  
  434.                 {  Debugging Methods     }
  435.  
  436.                 PROCEDURE TGridView.Fields(PROCEDURE
  437.                                            DoToField(fieldName: Str255;
  438.                                                      fieldAddr: Ptr;
  439.                                                      fieldType: INTEGER)); OVERRIDE;
  440.                 { Used by the Inspector and the Debugger to display the contents of this class's
  441.                 fields. }
  442.  
  443.                 END;
  444.  
  445.             TTextGridView        = OBJECT (TGridView)    { A sub-class of TGridView that can handle
  446.                                                          the display of text in its cells. }
  447.                 fTextStyle:         TextStyle;            { The text style (color, size, etc. ) }
  448.                 fLineHeight:        INTEGER;            { height of each item including leading }
  449.                 fLineAscent:        INTEGER;            { pos. of baseline relative to top of line }
  450.  
  451.                                 {  Initialization and Free Methods      }
  452.  
  453.                 PROCEDURE TTextGridView.ITextGridView(itsDocument: TDocument; { Its document }
  454.                                                       itsSuperView: TView; { Its parent view }
  455.                                                       itsLocation: VPoint; { Top, Left in parent's
  456.                                                           coords }
  457.                                                       itsSize: VPoint;
  458.                                                       itsHSizeDet, itsVSizeDet: SizeDeterminer; {
  459.                                                           Size determiners }
  460.                                                       numOfRows: INTEGER; { Number of rows initially
  461.                                                                            }
  462.                                                       numOfCols: INTEGER; { Number of columns
  463.                                                                            initially }
  464.                                                       rowHeight: INTEGER; { Height of rows, or zero
  465.                                                                            for font height }
  466.                                                       colWidth: INTEGER; { Width of items in the
  467.                                                                           columns }
  468.                                                       adornRows: BOOLEAN; { Adornment for Rows? }
  469.                                                       adornCols: BOOLEAN; { Adornment for Columns? }
  470.                                                       rowInset: INTEGER; { horizontal space between
  471.                                                                           cells }
  472.                                                       colInset: INTEGER; { vertical space between
  473.                                                                           cells }
  474.                                                       singleSelection: BOOLEAN; { single cell
  475.                                                           selection? }
  476.                                                       itsTextStyle: TextStyle); { size, color, etc.
  477.                     font info }
  478.  
  479.                 { Initialize the TextGridView. If numOfRows or numOfCols is non-zero then the
  480.                 gridview is initialized to the specified size. The row and height of the cells is
  481.                 determine by the font size, style etc. The default size may be changed with calls
  482.                 to the the SetRowHeight and SetColWidth methods. If either adorn is kDontAdorn,
  483.                 then that adorn will not be called. The "Insets" allow space between cells and may
  484.                 be used to draw row and column adornments. }
  485.  
  486.                 PROCEDURE TTextGridView.IRes(itsDocument: TDocument;
  487.                                              itsSuperView: TView;
  488.                                              VAR itsParams: Ptr); OVERRIDE;
  489.                 { Initialize the view template. }
  490.  
  491.                 PROCEDURE TTextGridView.WRes(theResource: ViewRsrcHndl;
  492.                                              VAR itsParams: Ptr); OVERRIDE;
  493.                 { Write this object out as a view resource. }
  494.  
  495.                 PROCEDURE TTextGridView.WriteRes(theResource: ViewRsrcHndl;
  496.                                                  VAR itsParams: Ptr); OVERRIDE;
  497.                 { Set up the type and signature of this object and call WRes. }
  498.  
  499.                 {  Methods To OVERRIDE      }
  500.  
  501.                 PROCEDURE TTextGridView.GetText(aCell: GridCell;
  502.                                                 VAR aString: Str255);
  503.                 { This routine gets the text to be draw in a given cell. IT MUST BE OVERRIDDEN! }
  504.  
  505.                 {  General Methods       }
  506.  
  507.                 PROCEDURE TTextGridView.DrawCell(aCell: GridCell;
  508.                                                  aQDRect: Rect); OVERRIDE;
  509.                 { Calls GetText and then draws the text }
  510.  
  511.                 FUNCTION TTextGridView.Focus: BOOLEAN; OVERRIDE;
  512.                 { Calls inherited focus and calls SetUpFont }
  513.  
  514.                 PROCEDURE TTextGridView.SetUpFont;
  515.                 { Sets up the font for this view. }
  516.  
  517.                 PROCEDURE TTextGridView.SetPen;
  518.                 { Sets the font characteristics of the current port. Called at the beginning of the
  519.                 Draw method.}
  520.  
  521.                 PROCEDURE TTextGridView.Fields(PROCEDURE
  522.                                                DoToField(fieldName: Str255;
  523.                                                          fieldAddr: Ptr;
  524.                                                          fieldType: INTEGER)); OVERRIDE;
  525.                 { Used by the Inspector and the Debugger to display the contents of this class's
  526.                 fields. }
  527.  
  528.                 END;
  529.  
  530.             TTextListView        = OBJECT (TTextGridView) { This subclass of TTextGridView handles
  531.                                                           lists in a manner similar to the List
  532.                                                           Manager in the toolbox. These lists
  533.                                                           typically consist of single columns and
  534.                                                           the case of this subclass handle the
  535.                                                           placeme { Initialization and Free Methods
  536.                                                           }
  537.  
  538.                 PROCEDURE TTextListView.ITextListView(itsDocument: TDocument; { Its document }
  539.                                                       itsSuperView: TView;
  540.                                                       itsLocation: VPoint;
  541.                                                       itsSize: VPoint;
  542.                                                       itsHSizeDet, itsVSizeDet: SizeDeterminer;
  543.                                                       numOfItems: INTEGER;
  544.                                                       rowHeight: INTEGER; { Height of rows, or zero
  545.                                                                            for font height }
  546.                                                       colWidth: INTEGER;
  547.                                                       adornRows: BOOLEAN;
  548.                                                       adornCols: BOOLEAN;
  549.                                                       rowInset: INTEGER;
  550.                                                       colInset: INTEGER;
  551.                                                       singleSelection: BOOLEAN;
  552.                                                       itsTextStyle: TextStyle);
  553.  
  554.                 { Initialize the TextListView. If numOfItems is non-zero then the listview is
  555.                 initialized to the specified size. The width and height of the items are determined
  556.                 by the font size, style etc. The default size may be changed with calls to the the
  557.                 SetItemHeight and SetItemWidth methods. The "Insets" allow space between items. }
  558.  
  559.                 PROCEDURE TTextListView.WriteRes(theResource: ViewRsrcHndl;
  560.                                                  VAR itsParams: Ptr); OVERRIDE;
  561.                 { Set up the type and signature of this object and call WRes. }
  562.  
  563.                 {  Methods To OVERRIDE      }
  564.  
  565.                 PROCEDURE TTextListView.GetItemText(anItem: INTEGER;
  566.                                                     VAR aString: Str255);
  567.                 { Get the text to be drawn for a given item. THIS METHOD MUST BE OVERRIDDEN !! }
  568.  
  569.                 FUNCTION TTextListView.CanSelectItem(anItem: INTEGER): BOOLEAN;
  570.                 { Determine if the item is selectable }
  571.  
  572.                 {  General Methods       }
  573.                 PROCEDURE TTextListView.AllItemsDo(PROCEDURE
  574.                                                    DoToItem(anItem: INTEGER));
  575.                 { For all the items in the view perform "DoToItem". }
  576.  
  577.                 FUNCTION TTextListView.CanSelectCell(aCell: GridCell): BOOLEAN; OVERRIDE;
  578.                 { This method checks to see if a cell can be selected. This method simply calls
  579.                 CanSelectItem }
  580.  
  581.                 PROCEDURE TTextListView.DelItemAt(anItem: INTEGER;
  582.                                                   numOfItems: INTEGER);
  583.                 { Delete the specified items.  This causes a redraw of only the necessary cells. }
  584.  
  585.                 PROCEDURE TTextListView.DelItemFirst(numOfItems: INTEGER);
  586.                 { Delete the specified items.  This causes a redraw of only the necessary cells. }
  587.  
  588.                 PROCEDURE TTextListView.DelItemLast(numOfItems: INTEGER);
  589.                 { Delete the specified items.  This causes a redraw of only the necessary cells. }
  590.  
  591.                 PROCEDURE TTextListView.EachItemDo(start, stop: INTEGER;
  592.                                                    PROCEDURE
  593.                                                    DoToItem(anItem: INTEGER));
  594.                 { For each item in the specified range perform "DoToItem". }
  595.  
  596.                 PROCEDURE TTextListView.EachSelectedItemDo(PROCEDURE
  597.                                                            DoToItem(anItem: INTEGER));
  598.                 { For each item selected perform "DoToItem". }
  599.  
  600.                 FUNCTION TTextListView.GetItemHeight(anItem: INTEGER): INTEGER;
  601.                 { Return the height of the specified item. }
  602.  
  603.                 FUNCTION TTextListView.GetItemWidth: INTEGER;
  604.                 { Return the width of the view. }
  605.  
  606.                 PROCEDURE TTextListView.GetText(aCell: GridCell;
  607.                                                 VAR aString: Str255); OVERRIDE;
  608.                 { Calls GetItemText with an item number. }
  609.  
  610.                 PROCEDURE TTextListView.InsItemBefore(anItem: INTEGER;
  611.                                                       numOfItems: INTEGER);
  612.                 { Insert numOfItems before anItem in the list. }
  613.  
  614.                 PROCEDURE TTextListView.InsItemFirst(numOfItems: INTEGER);
  615.                 { Insert numOfItems at the beginning of the list. }
  616.  
  617.                 PROCEDURE TTextListView.InsItemLast(numOfItems: INTEGER);
  618.                 { Insert numOfItems at the    end of the list. }
  619.  
  620.                 FUNCTION TTextListView.IsItemSelected(anItem: INTEGER): BOOLEAN;
  621.                 { Check if the specified item is currently selected. }
  622.  
  623.                 PROCEDURE TTextListView.Resize(width, height: VCoordinate;
  624.                                                invalidate: BOOLEAN); OVERRIDE;
  625.                 { Resize the view. }
  626.  
  627.                 PROCEDURE TTextListView.SelectCell(theCell: GridCell;
  628.                                                    extendSelection, highlight,
  629.                     select: BOOLEAN); OVERRIDE;
  630.                 { Calls SelectItem with the appropriate item number }
  631.  
  632.                 PROCEDURE TTextListView.SelectItem(anItem: INTEGER;
  633.                                                    extendSelection, highlight, select: BOOLEAN);
  634.                 { Select the given item. If extend is true then the item is added to the current
  635.                 selection. Otherwise the current selection is deselected. If highlight is true then
  636.                 the selected item is highlighted.}
  637.  
  638.                 PROCEDURE TTextListView.SetItemHeight(anItem: INTEGER;
  639.                                                       numOfItems: INTEGER;
  640.                                                       aHeight: INTEGER);
  641.                 { Set the height of an item to be different from the default.  This
  642.                 changes the height of only the specified items. }
  643.  
  644.                 PROCEDURE TTextListView.SetItemWidth(aWidth: INTEGER);
  645.                 { Set the width of the view to aWidth.    (This changes the width of all
  646.                 the items. }
  647.  
  648.                 FUNCTION TTextListView.FirstSelectedItem: INTEGER;
  649.                 { Returns the first item selected. }
  650.  
  651.                 FUNCTION TTextListView.LastSelectedItem: INTEGER;
  652.                 { Returns the last item selected. }
  653.  
  654.                 PROCEDURE TTextListView.InvalidateItem(anItem: INTEGER);
  655.                 { Invalidates the given item, causing it to be redrawn }
  656.  
  657.                 PROCEDURE TTextListView.Fields(PROCEDURE
  658.                                                DoToField(fieldName: Str255;
  659.                                                          fieldAddr: Ptr;
  660.                                                          fieldType: INTEGER)); OVERRIDE;
  661.                 { Used by the Inspector and the Debugger to display the contents of this class's
  662.                 fields. }
  663.  
  664.                 END;
  665.  
  666.             TCellSelectCommand    = OBJECT (TCommand)
  667.                 fGridView:            TGridView;            { The associated GridView }
  668.                 fShiftKey:            BOOLEAN;            { Shift Key down? }
  669.                 fCmdKey:            BOOLEAN;            { Command Key down? }
  670.                 fDeselecting:        BOOLEAN;
  671.                 fAnchorCell:        GridCell;
  672.                 fPrevCell:            GridCell;
  673.                 fThisSelection:     RgnHandle;
  674.                 fPrevSelection:     RgnHandle;
  675.                 fDifference:        RgnHandle;
  676.  
  677.                 PROCEDURE TCellSelectCommand.ICellSelectCommand(itsView: TGridView;
  678.                                                                 theShiftKey, theCmdKey: BOOLEAN);
  679.                 { Initialize the command object. }
  680.  
  681.                 PROCEDURE TCellSelectCommand.Free; OVERRIDE;
  682.                 { If the region fPrevSelection and fDifference are not NIL then dispose of them
  683.                 before calling inherited Free. }
  684.  
  685.                 PROCEDURE TCellSelectCommand.TrackFeedback(anchorPoint, nextPoint: VPoint;
  686.                                                            turnItOn,
  687.                     mouseDidMove: BOOLEAN); OVERRIDE;
  688.                 { Override this method to give feedback while the mouse button is down. The default
  689.                 does nothing. }
  690.  
  691.                 FUNCTION TCellSelectCommand.TrackMouse(aTrackPhase: TrackPhase;
  692.                                                        VAR anchorPoint, previousPoint,
  693.                                                        nextPoint: VPoint;
  694.                                                        mouseDidMove: BOOLEAN): TCommand; OVERRIDE;
  695.                 { Track the mouse when the button is down. }
  696.  
  697.                 PROCEDURE TCellSelectCommand.DoIt; OVERRIDE;
  698.                 { The method that will do the actual task to be performed by the command.  MUST BE
  699.                 OVERRIDDEN. }
  700.  
  701.                 PROCEDURE TCellSelectCommand.ComputeAnchorCell(VAR clickedCell: GridCell);
  702.                 { Computes the cell that the mouse is first clicked in when making a selection. }
  703.  
  704.                 PROCEDURE TCellSelectCommand.ComputeNewSelection(VAR clickedCell: GridCell);
  705.                 { Calculate what the new selection should be. }
  706.  
  707.                 PROCEDURE TCellSelectCommand.HighlightNewSelection;
  708.                 { Highlight the new selection. }
  709.  
  710.                 PROCEDURE TCellSelectCommand.Fields(PROCEDURE
  711.                                                     DoToField(fieldName: Str255;
  712.                                                               fieldAddr: Ptr;
  713.                                                               fieldType: INTEGER)); OVERRIDE;
  714.                 { Used by the Inspector and the Debugger to display the contents of this class's
  715.                 fields. }
  716.  
  717.                 END;
  718.  
  719.             TRCSelectCommand    = OBJECT (TCellSelectCommand)
  720.             { An abstract superclass for row and column selection }
  721.  
  722.                 PROCEDURE TRCSelectCommand.ComputeNewSelection(VAR clickedCell: GridCell); OVERRIDE;
  723.                 { Computes the new selection. }
  724.  
  725.                 FUNCTION TRCSelectCommand.TrackMouse(aTrackPhase: TrackPhase;
  726.                                                      VAR anchorPoint, previousPoint,
  727.                                                      nextPoint: VPoint;
  728.                                                      mouseDidMove: BOOLEAN): TCommand; OVERRIDE;
  729.                 { Track the mouse during selection. }
  730.  
  731.                 PROCEDURE TRCSelectCommand.Fields(PROCEDURE
  732.                                                   DoToField(fieldName: Str255;
  733.                                                             fieldAddr: Ptr;
  734.                                                             fieldType: INTEGER)); OVERRIDE;
  735.                 { Used by the Inspector and the Debugger to display the contents of this class's
  736.                 fields. }
  737.  
  738.                 END;
  739.  
  740.             TRowSelectCommand    = OBJECT (TRCSelectCommand) { A subclass that performs selections on
  741.                                                              rows. }
  742.                 PROCEDURE TRowSelectCommand.IRowSelectCommand(itsView: TGridView;
  743.                                                               theShiftKey, theCmdKey: BOOLEAN);
  744.                 { Initialization of command. }
  745.  
  746.                 PROCEDURE TRowSelectCommand.ComputeAnchorCell(VAR clickedCell: GridCell); OVERRIDE;
  747.                 { Override of method to perform computations specific to row selection. }
  748.  
  749.                 PROCEDURE TRowSelectCommand.ComputeNewSelection(VAR clickedCell: GridCell); OVERRIDE
  750.                     ;
  751.                 { Override of method to perfom computation of new selection specific to row
  752.                 selection. }
  753.                 PROCEDURE TRowSelectCommand.Fields(PROCEDURE
  754.                                                    DoToField(fieldName: Str255;
  755.                                                              fieldAddr: Ptr;
  756.                                                              fieldType: INTEGER)); OVERRIDE;
  757.                 { Used by the Inspector and the Debugger to display the contents of this class's
  758.                 fields. }
  759.  
  760.                 END;
  761.  
  762.             TColumnSelectCommand = OBJECT (TRCSelectCommand) { A subclass that handles the selection
  763.                                                               of columns in a GridView. }
  764.                 PROCEDURE TColumnSelectCommand.IColumnSelectCommand(itsView: TGridView;
  765.                                                                     theShiftKey,
  766.                                                                     theCmdKey: BOOLEAN);
  767.                 { Initialization method. }
  768.  
  769.                 PROCEDURE TColumnSelectCommand.ComputeAnchorCell(VAR clickedCell: GridCell);
  770.                     OVERRIDE;
  771.                 { Override of method to perform computations specific to column selection. }
  772.  
  773.                 PROCEDURE TColumnSelectCommand.ComputeNewSelection(VAR clickedCell: GridCell);
  774.                     OVERRIDE;
  775.                 { Override of method to perform computation of new selection specific to column
  776.                 selection. }
  777.  
  778.                 PROCEDURE TColumnSelectCommand.Fields(PROCEDURE
  779.                                                       DoToField(fieldName: Str255;
  780.                                                                 fieldAddr: Ptr;
  781.                                                                 fieldType: INTEGER)); OVERRIDE;
  782.                 { Used by the Inspector and the Debugger to display the contents of this class's
  783.                 fields. }
  784.  
  785.                 END;
  786.  
  787.         VAR
  788.         { These are intended to be private, but are in the interface so that you can use these
  789.         regions if you override the methods that use them. }
  790.  
  791.             pPixelsToHighlight: RgnHandle;                { Used by HighlightCells }
  792.             pPreviousSelection: RgnHandle;                { Used by SetSelection }
  793.             pDifference:        RgnHandle;                { Used by SetSelection }
  794.             pVisibleCells:        RgnHandle;                { Used by CellsToPixels }
  795.             pInvalidateRgn:     RgnHandle;                { Used by InvalidateSelection }
  796.  
  797.         PROCEDURE InitUGridView;
  798.                 { Creates all the regions used by the GridView class and then sets the global flag
  799.                 'gUGridViewInitialized'. }
  800.  
  801.         {$ENDC}
  802.  
  803.         {$IFC NOT UsingIncludes}
  804. END.
  805. {$ENDC}
  806.